import json
from common.models import ImageForm
from django.http import HttpResponse


def upload_file(request):
    if request.method == "POST":
        image = ImageForm(request.POST, request.FILES)
        if image.is_valid():
            image.save()
            return HttpResponse(json.dumps({
                "code": "200",
                "msg": "success",
                "data": image.get_image_url(),
            }))

    return HttpResponse(json.dumps({
        "code": "400",
        "msg": "fail",
        "data": None,
    }))
